var testCheckGrid = Ext.create('Ext.tree.Panel', {
    header: false,
    useArrows: true,
    rootVisible: false,
    store: testCheckGridStore,
    layout: 'fit',
    dockedItems: [{
        xtype: 'toolbar',
        items: [{
            xtype: 'combo',
            fieldLabel: '审核对象类型',
            itemId: 'testCheckGridTypeCombo',
            emptyText: '类型',
            editable: false, // 防止用户直接在下拉框里输入
            width: 200,
            labelWidth: 90,
            queryMode: 'local',
            displayField: 'typeName',
            valueField: 'typeNum',
            store: testCheckGridTypeComboStore,
            listeners: {
                change: function (combo, newValue, oldValue, eOpts) {
                    var statusValue = testCheckGrid.down('#testCheckGridStatusCombo').value;
                    if (statusValue != null) // 要在状态选择框也被选择了的情况下才会去执行
                        getTestCheckByCombo(newValue, statusValue);
                }
            }
        }, '-', {
            xtype: 'combo',
            itemId: 'testCheckGridStatusCombo',
            fieldLabel: '审核对象状态',
            emptyText: '状态',
            editable: false, // 防止用户直接在下拉框里输入
            width: 200,
            labelWidth: 90,
            store: testCheckGridStatusComboStore,
            queryMode: 'local',
            displayField: 'statusText',
            valueField: 'statusNum',
            listeners: {
                change: function (combo, newValue, oldValue, eOpts) {
                    var typeValue = testCheckGrid.down('#testCheckGridTypeCombo').value;
                    if (typeValue != null) // 要在类型选择框也被选择了的情况下才会去执行
                        getTestCheckByCombo(typeValue, newValue);
                }
            }
        }, '-', {
            text: '通过',
            tooltip: '通过审核',
            icon: 'static/images/icons/fam/accept.png',
            listeners: {
                click: function () {
                    judgeCheck(1);
                }
            }
        }, '-', {
            text: '不通过',
            tooltip: '不通过审核',
            icon: 'static/images/icons/fam/cross.gif',
            listeners: {
                click: function () {
                    judgeCheck(0);
                }
            }
        }]
    }],
    columns: [{
        xtype: 'treecolumn', // this is so we know which column will show the
        // tree
        text: '昵称',
        width: 250,
        dataIndex: 'targetName',
        flex:1
        // locked: true
    }, {
        // we must use the templateheader component so we can use a custom tpl
        text: '所属主题',
        width: 200,
        sortable: true,
        dataIndex: 'folderPath',
        align: 'center',
    }, {
        text: '审核结果',
        width: 150,
        sortable: true,
        align: 'center',
        dataIndex: 'result',
        renderer: function (value) {
            if (value == '审核通过')
                return '<img src="static/images/icons/fam/accept.png" style="margin:0px 20px 0px 0px;vertical-align:text-top;"  />' + '<span>' + value + '</span>';
            else if (value == '审核未通过')
                return '<img src="static/images/icons/fam/cross.gif" style="margin:0px 10px 0px 0px;vertical-align:text-top;"/>' + '<span>' + value + '</span>';
            else
                return '<img src="static/images/icons/fam/warning.ico" style="margin:0px 32px 0px 0px;vertical-align:text-top;"/>' + '<span>' + value + '</span>';
        }
    }, {
        text: '审核时间',
        dataIndex: 'checkDate',
        width: 200,
        align: 'center',
        stopSelection: false,
        renderer: function (value) {
            if (value == null)
                return "无"
            return value.replace('T', '  ');
        }
    }, {
        text: '查看详情',
        align: 'center',
        sortable: false,
        xtype: 'actioncolumn',
        width: 90,
        items: [{
            icon: 'static/images/icons/fam/look.ico',
            tooltip: '查看详情',
            handler: function (grid, rowIndex, colIndex, actionItem, event, record, row) {
                Ext.getCmp('centerRegion').removeAll(false);
                var typeValue = testCheckGrid.down('#testCheckGridTypeCombo').value;
                if (typeValue == 0) {//如果是审核测试需求的话
                    Ext.getCmp('centerRegion').add(testRequirementCheckForm);
                    testRequrementCheckFormReset();
                    testRequrementCheckDataToForm(record);
                } else if (typeValue == 1) {//如果是审核测试计划
                    Ext.getCmp('centerRegion').add(testDesignCheckTabPanel);
                    testDesignCheckFormReset();
                    testDesignCheckDataToForm(record);
                } else if (typeValue == 2) {//如果是审核测试执行
                    Ext.getCmp('centerRegion').add(testRunCheckTabPanel);
                    testRunCheckTabPanel.setActiveTab(0);
                    testRunCheckFormReset();
                    testRunCheckDataToForm(record);
                }
            }
        }]
    }, {
        text: '操作',
        width: 90,
        menuDisabled: true,
        xtype: 'actioncolumn',
        tooltip: '授权他人审核',
        align: 'center',
        icon: 'static/images/icons/fam/rss_go.png',
        handler: function (grid, rowIndex, colIndex, actionItem, event, record, row) {
        },
        // Only leaf level tasks may be edited
        isDisabled: function (view, rowIdx, colIdx, item, record) {
            return record.data.parentId != 'root';
        }
    }],
    listeners: [{
        beforeitemexpand: function (record, eOpts) {
            expendItem(record);
        }
    }],
    selModel: testCheckGirdCheckBox
});

//审核时用于显示测试计划的测试步骤的grid
var testDesignCheckStepGrid = Ext.create('Ext.grid.Panel', {
    store: testDesignStepStore,
    columns: [new Ext.grid.RowNumberer(),//显示行号
        {
            text: '名称',
            width: 100,
            dataIndex: 'name',
            sortable: false
        }, {
            text: '内容',
            dataIndex: 'description',
            flex: 1,
            sortable: false,
            renderer: function (v, m, r) {
                if (v.length < 15)
                    return v;
                else
                    return '内容过长,请展开查看';
            }
        }, {
            text: '期望结果',
            dataIndex: 'expectedResult',
            flex: 0.5,
            sortable: false
        }],
    plugins: {
        rowexpander: {
            rowBodyTpl: new Ext.XTemplate(
                '{description}'
            )
        }
    }
});

//审核时用于显示测试计划的关联测试需求的grid
var testDesignCheckTestRequirementGrid = Ext.create('Ext.grid.Panel', {
    store: testDesignTestRequirmentStore,
    columns: [new Ext.grid.RowNumberer(),//显示行号
        {
            text: '名称',
            width: 100,
            dataIndex: 'title',
            sortable: false
        }, {
            text: '编写者',
            dataIndex: 'author',
            flex: 0.5,
            sortable: false
        }, {
            text: '内容',
            dataIndex: 'description',
            flex: 1,
            sortable: false,
            renderer: function (v, m, r) {
                if (v.length < 15)
                    return v;
                else
                    return '内容过长,请展开查看';
            }
        }],
    plugins: {
        rowexpander: {
            rowBodyTpl: new Ext.XTemplate(
                '{description}'
            )
        }
    }
});

//审核时用于显示测试执行记录的外层grid
var testRunCheckLogGrid = Ext.create('Ext.grid.Panel', {
    alias: 'widget.MainGrid',
    header: false,
    height: '60%',
    border: false,
    store: testRunlogRowWidGetStore,
    columns: [new Ext.grid.RowNumberer(), {
        text: "测试机",
        dataIndex: 'host',
        sortable: false
    }, {
        text: "状态",
        dataIndex: 'status',
        sortable: false,
        renderer: function (value) {
            if (value == -1)
                return "<img src='static/images/icons/fam/warning.ico' style='vertical-align:text-top;'  />未完成";
            else if (value == 0)
                return "<img src='static/images/icons/fam/cross.gif' style='vertical-align:text-top;'  /> 失败";
            else
                return "<img src='static/images/icons/fam/accept.png' style='vertical-align:text-top;'  />成功";
        },
    }, {
        text: "执行时长",
        sortable: false,
        dataIndex: 'duration',
    }, {
        text: "浏览器版本",
        sortable: false,
        dataIndex: 'browserVersion',
    }, {
        text: "操作系统",
        sortable: false,
        dataIndex: 'os',
    }, {
        text: "创建时间",
        sortable: false,
        dataIndex: 'createDate',
        flex: 0.5,
        renderer: function (value) {
            if (value == null)
                return '无';
            else
                return value.replace('T', '  ');
        }
    }],
    selModel: {
        selType: 'cellmodel'
    },
    plugins: [{
        ptype: 'rowwidget',
        widget: {
            xtype: 'grid',
            bind: {
                store: '{record.testRunLogStep}',
            },
            header: false,
            selModel: {
                selType: 'cellmodel'
            },
            columns: [new Ext.grid.RowNumberer(),
                {
                    text: "步骤名称",
                    dataIndex: 'name',
                    flex: 0.5,
                    sortable: false,
                }, {
                    text: "状态",
                    dataIndex: 'isPass',
                    sortable: false,
                    renderer: function (value) {
                        if (value == -1)
                            return "<img src='static/images/icons/fam/warning.ico' style='vertical-align:text-top;'  />未完成";
                        else if (value == 0)
                            return "<img src='static/images/icons/fam/cross.gif' style='vertical-align:text-top;'  /> 失败";
                        else
                            return "<img src='static/images/icons/fam/accept.png' style='vertical-align:text-top;'  />成功";
                    }
                },
                {
                    text: "理由",
                    dataIndex: 'reason',
                    flex: 1,
                    sortable: false,
                    renderer: function (v, m, r) {
                        if (v == null)//不知道为什么如果显示的是null就无法触发点击事件
                            return '';
                        else if (v.length < 15)
                            return v;
                        else
                            return '内容过长,请展开查看';
                    }
                }
            ],
//			columnLines: true,
//			autoWidth: true,
//			autoHeight: true,
            // width: 400,renderId
            // height: 200,
            iconCls: 'icon-grid',
            plugins: {
                rowexpander: {
                    rowBodyTpl: new Ext.XTemplate(
                        '{reason}'
                    )
                }
            }
        }

    }],
    collapsible: true,
    animCollapse: false,
    iconCls: 'icon-grid',
    listeners: [{
        itemclick: function (view, record, item, index, e, eOpts) {//当选择对应的执行记录时，下面的测试步骤详情也要随之改变
            testRunLogStepRowWidGetStore.removeAll();
            testRunLogStepRowWidGetStore.setData(testDesignBorderShot(record.data.testRunLogStep));
        }
    }]
});


//用于测试时显示测试执行的测试步骤的详细信息grid
var testRunCheckLogStepGrid = Ext.create('Ext.grid.Panel', {
    store: testRunLogStepRowWidGetStore,
//    collapsible: true, // 有没有按钮向内缩进
//    collapseDirection:'left',
//    titleAlign:'right',
//    headerPosition:'right',
    header: {
        height: 23,
        padding: '2 0 2 10 '
    },
    title: '测试步骤信息',
    border: false,
    height: '40%',
    columns: [new Ext.grid.RowNumberer(),// 显示行号
        {
            text: '名称',
            width: 100,
            dataIndex: 'name',
            sortable: false
        }, {
            text: '内容',
            dataIndex: 'description',
            flex: 1,
            sortable: false,
            renderer: function (v, m, r) {
                if (v.length < 15)
                    return v;
                else
                    return '内容过长,请展开查看';
            }
        }, {
            text: '期望结果',
            dataIndex: 'expectedResult',
            flex: 0.5,
            sortable: false
        }],
    plugins: {
        rowexpander: {
            rowBodyTpl: new Ext.XTemplate(
                '{description}'
            )
        }
    }
});